package cn.vihub.controller;

import cn.vihub.param.ShopGoodsAttributeGroupParam;
import cn.vihub.param.ShopGoodsAttributeParam;
import cn.vihub.pojo.ShopGoodsAttribute;
import cn.vihub.pojo.ShopGoodsAttributeGroup;
import cn.vihub.service.ShopGoodsAttributeGroupService;
import cn.vihub.service.ShopGoodsAttributeService;
import cn.vihub.utils.Result;
import cn.vihub.vo.ShopAttributeGroupVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 秋晚
 * @Date: 2025/7/25 20:21
 * @Description:
 **/
@RestController
@RequestMapping("shop-store/goodsAttribute")
public class ShopGoodsAttributeController {

    @Autowired
    ShopGoodsAttributeService shopGoodsAttributeService;

    @Autowired
    ShopGoodsAttributeGroupService shopGoodsAttributeGroupService;
    /**
     * @author: 秋晚
     * @description:分页根据分组id查询商品
     * @params: []
     * @return: cn.vihub.utils.Result<com.baomidou.mybatisplus.core.metadata.IPage<cn.vihub.pojo.ShopGoodsAttribute>>
     * @date: 2025/7/25 20:22
     */
    @PostMapping("shopGoodsPage")
    public Result<IPage<ShopGoodsAttribute>> shopGoodsPage(@RequestBody ShopGoodsAttributeParam shopGoodsAttributeParam){
        return Result.success(shopGoodsAttributeService.shopGoodsPage(shopGoodsAttributeParam));
    }




    /**
     * @author: 秋晚
     * @description:添加或编辑用户
     * @params: [cn.vihub.param.ShopGoodsAttributeParam]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/7/25 20:50
     */
    @PostMapping("saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody ShopGoodsAttributeParam shopGoodsAttributeParam){
        //创建实体类对象
        ShopGoodsAttribute shopGoodsAttribute = new ShopGoodsAttribute();
        //拷贝
        BeanUtils.copyProperties(shopGoodsAttributeParam,shopGoodsAttribute);

        //进行添加或修改
        return Result.success(shopGoodsAttributeService.saveOrUpdate(shopGoodsAttribute));
    }


    /**
     * @author: 秋晚
     * @description:
     * @params: [java.lang.Integer]
     * @return: cn.vihub.utils.Result<java.lang.Boolean> 
     * @date: 2025/7/25 20:52
     */
    @DeleteMapping("deleteById/{id}")
    public Result<Boolean> deleteById(@PathVariable(name = "id")Integer id){
        return Result.success(shopGoodsAttributeService.removeById(id));
    }

    /**
     * @author: 秋晚
     * @description:分页根据分组id查询商品
     * @params: []
     * @return: cn.vihub.utils.Result<com.baomidou.mybatisplus.core.metadata.IPage<cn.vihub.pojo.ShopGoodsAttribute>>
     * @date: 2025/7/25 20:22
     */
    @GetMapping("shopGoodsGroupPage")
    public Result<IPage<ShopGoodsAttributeGroup>> shopGoodsGroupPage(ShopGoodsAttributeGroupParam shopGoodsAttributeGroupParam){
        return Result.success(shopGoodsAttributeGroupService.shopGoodsPage(shopGoodsAttributeGroupParam));
    }


    /**
     * @author: 秋晚
     * @description:添加或编辑用户
     * @params: [cn.vihub.param.ShopGoodsAttributeParam]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/7/25 20:50
     */
    @PostMapping("saveOrUpdateByGroup")
    public Result<Boolean> saveOrUpdateByGroup(@RequestBody ShopGoodsAttributeGroupParam shopGoodsAttributeGroupParam){
        //创建实体类对象
        ShopGoodsAttributeGroup shopGoodsAttributeGroup = new ShopGoodsAttributeGroup();
        //拷贝
        BeanUtils.copyProperties(shopGoodsAttributeGroupParam,shopGoodsAttributeGroup);

        //进行添加或修改
        return Result.success(shopGoodsAttributeGroupService.saveOrUpdate(shopGoodsAttributeGroup));
    }


    /**
     * @author: 秋晚
     * @description:
     * @params: [java.lang.Integer]
     * @return: cn.vihub.utils.Result<java.lang.Boolean>
     * @date: 2025/7/25 20:52
     */
    @DeleteMapping("deleteByIdGroup/{id}")
    public Result<Integer> deleteByIdGroup(@PathVariable(name = "id")Integer id){
        return Result.success(shopGoodsAttributeGroupService.deleteGroupById(id));
    }


    /**
     * @author: 秋晚
     * @description:获取属性分组和每个属性分组下的属性集合
     * @params: []
     * @return: cn.vihub.utils.Result<java.lang.Object>
     * @date: 2025/7/30 16:05
     */
    @GetMapping("getGroupData")
    public Result<List<ShopAttributeGroupVo>> getGroupData(){
        return Result.success(shopGoodsAttributeGroupService.getGroupData());
    }
}
